package com.sky.controller.user;


import com.sky.dto.SetmealDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-套餐接口")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    @GetMapping("/list")
    @ApiOperation("根据分类查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> list(@RequestParam Integer categoryId) {
        log.info("查询套餐：{}",categoryId);
        List<Setmeal> setmealList = setmealService.queryByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    //根据套餐id查询菜品
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询菜品")
    @Cacheable(cacheNames = "dishCache",key = "#id")
    public Result<List<DishItemVO>> queryBySetmealId(@PathVariable("id") Long id) {
        log.info("查询菜品：{}",id);
        List<DishItemVO> dishList = setmealService.queryDishById(id);
        return Result.success(dishList);
    }


}
